# Binary file
BIN			= part2D

# Flags
#/opt/cuda for mini
#/opt/cudasdk for mini
#lib64 for mini
CUDA_INSTALL_PATH	= /usr/local/cuda
CUDASDK_INSTALL_PATH	= /usr/nvidia/cudasdk
CUDA_LIB_PATH		= $(CUDA_INSTALL_PATH)/lib64
CUDASDK_LIB_PATH	= $(CUDASDK_INSTALL_PATH)/C/lib
INCLUDES		+= -I. -I$(CUDA_INSTALL_PATH)/include -I$(CUDASDK_INSTALL_PATH)/C/common/inc
LIBS			= -L$(CUDA_LIB_PATH) -L$(CUDASDK_LIB_PATH) 
CFLAGS			= -O3  -pthread -Wall -Wextra -ansi -pedantic
LDFLAGS			= -lrt -lm -lcudart
NVCC_FLAGS		= -O3 --compiler-options "-pthread"  -arch=sm_30 --ptxas-options=-v --use_fast_math

# Default Values
DEPTH           = 8
L			    = 128
SAMPLES			= 1
TEMP    		= 0.71f
TRAN			= 1
TMAX			= 5000
DELTA_T			= 100
OFILE			= [CUDA,$(DEPTH),$(L),$(SAMPLES),$(TEMP),$(TRAN),$(TMAX),$(DELTA_T)].dat

# Simulation Parameters
#-DCOUNT_ALL_GRAINS para contar en 3D
PARAMETERS		=  -DQ=$(Q) -DDEPTH=$(DEPTH) -DL=$(L) -DSAMPLES=$(SAMPLES) \
			  -DTEMP_MIN=$(TEMP_MIN) -DTEMP_MAX=$(TEMP_MAX) -DDELTA_TEMP=$(DELTA_TEMP) \
			  -DTRAN=$(TRAN) -DTMAX=$(TMAX) -DDELTA_T=$(DELTA_T)

# Compilers
NVCC			= $(CUDA_INSTALL_PATH)/bin/nvcc
GCC			    = gcc
LINKER			= gcc

# Files
C_SOURCES		=
CU_SOURCES		= part_2D.cu
HEADERS			=
C_OBJS			= $(patsubst %.c, %.o, $(C_SOURCES))
CU_OBJS			= $(patsubst %.cu, %.o, $(CU_SOURCES))


# Rules
$(BIN): clean $(C_OBJS) $(CU_OBJS) $(HEADERS)
	$(LINKER) -o $(BIN) $(CU_OBJS) $(C_OBJS) $(LDFLAGS) $(INCLUDES) $(LIBS)

$(C_OBJS): $(C_SOURCES) $(HEADERS)
	$(CC) -c $(C_SOURCES) $(CFLAGS) $(INCLUDES)

$(CU_OBJS): $(CU_SOURCES) $(HEADERS)
	$(NVCC) $(NVCC_FLAGS) -c $(CU_SOURCES) $(PARAMETERS) $(INCLUDES)

run: $(BIN)
	LD_LIBRARY_PATH=$(CUDA_LIB_PATH) ./$(BIN) > $(OFILE) &

clean:
	rm -f $(BIN) *.o *.linkinfo cuda_profile_?.log
